﻿using nplJobsCommon.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Select
{
   
    /// <summary>
    /// Select job type from the database
    /// </summary>
    public class SelectJobType : DataAccessBase
    {
        public SelectJobType()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectJobType.ToString();
        }

        #region GetJobType
        public List<JobType> GetJobType()
        {
            DataBaseHelper dbHelper;
            DataSet dsJobType;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsJobType = dbHelper.Run(base.ConnectionString);
                return GetList(dsJobType);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<JobType> GetList(DataSet dsJobType)
        {
            List<JobType> jobTypes;
            try
            {
                jobTypes = (from d in dsJobType.Tables[0].AsEnumerable()
                                 select new JobType
                                 {
                                     ID = d.Field<int>("ID"),
                                     Type = d.Field<string>("Type")
                                 }).ToList();

                return jobTypes;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
